<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.dao.TitlePostManageGroupDao"%>
<%@page import="java.util.Calendar"%>
<%@page import="com.shsh.safemanage.dao.DepartmentDao"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="com.shsh.safemanage.model.ProblemTransfer"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.model.Problem"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.model.Role"%>
<%@page import="com.shsh.safemanage.model.JobPost"%>
<%@page import="com.shsh.safemanage.model.Tendency"%>
<%@page import="com.shsh.safemanage.model.TendencyType"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.ProblemDao"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.action.WriteProblemAction"%>
<%@page import="com.shsh.safemanage.action.UserAction"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.Util"%>

<%
session.removeAttribute(Constants.SESSION_MANAGE_GROUP_USER);
session.removeAttribute(Constants.SESSION_PROBLEM_DEPARTMENT1);

String problemIDStr = request.getParameter(Constants.REQUEST_PARAMETER_ID);
Long problemID = 0L;
try {
	problemID = new Long(problemIDStr);
} catch (Exception e) {
}

String transferIDStr = request.getParameter(Constants.REQUEST_PARAMETER_TRANSFER_ID);
Long transferID = 0L;
try {
	transferID = new Long(transferIDStr);
} catch (Exception e) {
}

DepartmentDao departmentDao = DaoCreator.createDepartmentDao();
ProblemDao problemDao = DaoCreator.createProblemDao();

String fromPage = request.getParameter(Constants.REQUEST_PARAMETER_FROM_PAGE);


TitlePostManageGroupDao titlePostManageGroupDao = DaoCreator.createTitlePostManageGroupDao();
WriteProblemAction writeProblemAction = ActionCreator.createWriteProblemAction();
UserAction userAction = ActionCreator.createUserAction();

Problem problem = problemDao.getProblemByID(problemID);
List<TendencyType> tendencyTypeList = problemDao.getTendencyTypeList();

String initDateEndStr = Util.formatDate(problem.getWriteTime());

User user = (User) session.getAttribute(Constants.SESSION_USER);
JobPost post1 = titlePostManageGroupDao.getJobPostByID(user.getJobPost1ID());
JobPost post2 = titlePostManageGroupDao.getJobPostByID(user.getJobPost2ID());
JobPost post3 = titlePostManageGroupDao.getJobPostByID(user.getJobPost3ID());
Role theRole = userAction.getUserRole(request);

int role = writeProblemAction.calRole(post1, post2, post3, theRole);
%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; 事苗填报
</div>

<div class="tt">事苗报告</div>
<div class="content">
	<table align="center" border="1" width="99%" cellpadding="0"
		cellspacing="0">
		<tr>
			<td class="td1" colspan="2">
				<span style="margin-left: 30px; font-weight: bold">作业部（业务中心）：</span> <span><%=problem.getDepartment1Name()%></span>
				<span style="margin-left: 30px; font-weight: bold">装置：</span> <span><%=problem.getEquipmentName()%></span>
				<span style="margin-left: 30px; font-weight: bold">事苗类型：</span>
				<span>
					<select id="tendencyType">
					<%for (TendencyType tendencyType : tendencyTypeList) {%>
						<option value="<%=tendencyType.getId()%>"><%=tendencyType.getTendencyType()%></option>
					<%} %>
					</select>
				</span>
			</td>
		</tr>
	<tr>
			<td class="td1" width="60%">			
				<span style="margin-left: 30px; font-weight: bold">事苗名称：</span>  <br/>
				<span style="margin-left: 30px; ">
						<textarea rows="3" style="width:90%;" id="problemTitle"><%=problem.getProblemTitle()%></textarea>	
				</span>	
			</td>
			<td  class="td1" width="40%">
				<span style="margin-left: 30px; font-weight: bold">事苗发生时间：</span>
				<input  style="margin-left: 5px; " type="text" id="writeDate" size="15" onfocus="WdatePicker({maxDate:'#F{\'2050-12-31\'}'})" value="<%=initDateEndStr%>"/>
			</td>	
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">事苗经过：</span> <br/>
			<span style="margin-left: 30px; ">
			<textarea rows="5"  style="width:90%;" id="problemContent"><%=problem.getProblemContent()%></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">直接经济损失与间接经济损失：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea rows="5"  style="width:90%;" id="loss"></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">事苗原因：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea rows="10"  style="width:90%;" id="reason"></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">事苗教训及防范措施：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea rows="10"  style="width:90%;" id="zhenggai_cuoshi"><%=problem.getProblemZhenggai()%></textarea>	
			</span>
		</td>
	</tr>
		<tr>
			<td class="td1" colspan="2">
				<span style="margin-left: 30px" class="span1">填报人及时间：</span>
				<span><%=user.getDepartment1Name()%>-<%=user.getDepartment2Name()%>-<%=user.getDepartment3Name()%></span>
				<span><%=user.getName()%></span>
				<span><%=Util.formatDateTime(Calendar.getInstance())%></span>
			</td>
		</tr>
		<tr>
			<td class="td1" align="center" colspan="2">
				<% if(!"postcheckReport".equals(fromPage)) {%>
				<input type="button" value="转化" onclick="convertProblem()" />
				<%} %>
				<input type="button" value="取 消" style="margin-left: 20px" onclick="cancelConvert()" />
			</td>
		</tr>
	</table>
</div>

<script type="text/javascript">
function convertProblem() {	
	var tendencyTypeID = getElementValueByID("tendencyType");
	var problemTitle = getElementValueByID("problemTitle");
	var writeDate = getElementValueByID("writeDate");
	var problemContent = getElementValueByID("problemContent");
	var loss = getElementValueByID("loss");
	var reason = getElementValueByID("reason");
	var zhenggai_cuoshi = getElementValueByID("zhenggai_cuoshi");
	
	if ($.dialog.confirm('您确定转换此问题为事苗报告吗？', function(){
		openWaitingDialog('waitingDialog');
		$.ajax({
			type:'post',
			url:'convert_tendency_process.jsp',
			data:{
				problemID: <%=problemID%>,
				tendencyTypeID: tendencyTypeID,
				problemTitle: problemTitle,
				writeDate: writeDate,
				problemContent: problemContent,
				loss: loss,
				reason: reason,
				zhenggai_cuoshi: zhenggai_cuoshi
			},
			success:function(data,state,xmlhttp){
				var obj = null;
				try {
					obj = eval('(' + data + ')');
				} catch (e) {
				}
				if (typeof(obj.isSuccess) != 'undefined') {
					closeWaitingDialog('waitingDialog');
					if (obj.isSuccess == 'true') {
						$.dialog('问题转换成功！', function() { loadPageSection('<%=request.getContextPath()%>/problems_tobe_tendency.jsp', 'mainContentDiv'); });
					} else {
						$.dialog.alert(obj.error);
					}
				}
			}
		});
	}, function(){}));
}

function cancelConvert() {
	$.dialog.confirm('您确定取消此次转换吗？', function() {
		loadPageSection(
				'<%=request.getContextPath()%>/problems_tobe_tendency.jsp', 
				'mainContentDiv', 
				{
					
				}				
			);
	}, function(){});
}

function chooseProcessMethod(method) {
	if (method == 1) {
		document.getElementById('informedPersonsTR').style.display = 'none';
		document.getElementById('feedback').readonly = true;
		setElementValueByID('feedback', '<%=user.getDepartment1Name()%>，<%=user.getJobPost1Name()%><%=user.getName()%>确认该问题已整改');
	} else if (method == 2) {
		document.getElementById('informedPersonsTR').style.display = '';
		document.getElementById('feedback').readonly = false;
		setElementValueByID('feedback', '');
	} else if (method == 4 || method == 3 || method == 5 || method == 6 || method == 0) {
		document.getElementById('informedPersonsTR').style.display = 'none';
		setElementValueByID('feedback', '');
	}
}
</script>
